home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / PULLTEXT.HDR < prev    next >
Text File  |  1994-04-25  |  5KB  |  189 lines

  1. /******************************************************************************
  2.                  The Klipper Library, for CA-Clipper 5.x
  3.         Copyright (c), 1994, Wallace Information Systems Engineering
  4.  
  5. FUNCTION:
  6.  
  7. _PullText( nFile, cFromText, cToText ) --> cString
  8.  
  9. PARAMETERS:
  10.  
  11. nFile    : File handle of previously opened text file
  12. cFromText: Text to copy FROM but not including
  13. cToText  : Text to copy TO but not including
  14.  
  15. SHORT:
  16.  
  17. _PullText extracts lines from a text file between two tokens.
  18.  
  19. DESCRIPTION:
  20.  
  21. _PullText() scans an ASCII TEXT file, line by line, looking for the occurance
  22. of the cFromText token.
  23.  
  24. When and if it is found, text is copied from the line following until the
  25. end token is reached, or the end of file is encountered.
  26.  
  27. The tokens MUST MATCH CASE.  Case *is* sensitive.
  28.  
  29. The Begin and end tokens must appear on a line by themselves at column one.
  30.  Anything following the token on that line is ignored.  Text is read
  31. starting at the first line AFTER the begin token and ends on the first
  32. line BEFORE the end token.
  33.  
  34. Notes:
  35.  
  36. 1. If no cFromText token exists, _PullString() will return an empty string.
  37.  
  38. 2. If cFromText token DOES exist, but cToText token DOES NOT exist, you are
  39. going to get back the entire file, from the cFromText point all the way to
  40. the bottom of the file, including ALL the other begin and end tokens and
  41. their text as well as anything you have "embedded" between the tokens in
  42. "unused" areas.
  43.  
  44. NOTE:
  45.  
  46.  
  47.  
  48. EXAMPLE:
  49.  
  50. A VERY short example.  The following text file is for ALL of the
  51. following examples.
  52.  
  53. <************** TOP OF PULLTEXT.TXT FILE *****************>
  54.  
  55. |------ Column Position ------|
  56. 1         2         3
  57. 0....5....0....5....0....5....0
  58.  
  59. Tom, the plaintiff, made these comments on 11.23.93
  60.  
  61. :BeginThomas
  62. Hi!  I'm Tom.  Edward and Percy bonked me on the
  63. head yesterday.
  64. :EndTom
  65.  
  66. Following are Edward's Comments.
  67.  
  68. :BeginEdward
  69. Hullo!  I'm Edward.  Percy did it all by 'imself.
  70. :EndEdward
  71.  
  72. Percival's comments were made on 11/23/93
  73.  
  74. #BeginPercy
  75. Percival Here!  That's a damned lie. Both of them.
  76. I was never near the place.
  77. #EndPercy
  78.  
  79. (*** The judge delivers the sentence ***)
  80.  
  81. !BeginJudge
  82. Guilty!  Life!
  83. !EndJudge
  84.  
  85. <****************** EOF PULLTEXT.TXT FILE ***************>
  86.  
  87. Examples:
  88.  
  89.  
  90. nFile = fopen('case.txt')
  91.  
  92. *******************************************************
  93. * FIRST PULL note that the begin and end tokens       *
  94. * are slightly different.  That's fine.  call them    *
  95. * whatever you like, just be sure you call them right.*
  96. *******************************************************
  97.  
  98. ? _PullText(nFile,':BeginThomas',':EndTom')
  99.  
  100. "Hi!  I'm Tom.  Edward and Percy bonked me on the
  101. head yesterday."
  102.  
  103. ***************
  104. * SECOND PULL *
  105. ***************
  106.  
  107. ? _PullText(nFile,':BeginEdward',':EndEdward')
  108.  
  109. "Hullo!  I'm Edward.  Percy did it all by 'imself."
  110.  
  111. ******************************************************
  112. * THIRD PULL - notice the different tokens for this  *
  113. * one.  This is fine.  Again, you can use anything   *
  114. * you like, and as many different tokens as you      *
  115. * like - just remember what they are.  Personally    *
  116. * I'd recommend using the same tokenizing pattern.   *
  117. ******************************************************
  118.  
  119. ? _PullText(nFile,'#BeginPercy','#EndPercy')
  120.  
  121. "Percival Here!  That's a damned lie. Both of them.
  122. I was never near the place."
  123.  
  124. *************
  125. * FNAL PULL *
  126. *************
  127.  
  128. ? _PullText(nFile,'!BeginJudge','!EndJudge')
  129. "Guilty!  Life!"
  130.  
  131. *----------------------------------------------------------*
  132.  
  133.  
  134. If you looked at it this way:
  135.  
  136. ? _PullText(nFile,':BeginThomas',':EndTom')
  137. ?
  138. ? _PullText(nFile,':BeginEdward',':EndEdward')
  139. ?
  140. ? _PullText(nFile,'#BeginPercy','#EndPercy')
  141. ?
  142. ? _PullText(nFile,'!BeginJudge','!EndJudge')
  143.  
  144. Hi!  I'm Tom.  Edward and Percy bonked me on the
  145. head yesterday.
  146.  
  147. Hullo!  I'm Edward.  Percy did it all by 'imself.
  148.  
  149. Percival Here!  That's a damned lie. Both of them.
  150. I was never near the place.
  151.  
  152. Guilty!  Life!
  153.  
  154. Watch Out for the following:
  155.  
  156. ? _PullText(nFile,'#BeginPercy','#Endpercy')
  157. ?
  158. ? _PullText(nFile,'!BeginJudge','!EndJudge')
  159.  
  160.  
  161. Result:
  162.  
  163.     Percival Here!  That's a damned lie. Both of them.
  164.     I was never near the place.
  165.     #EndPercy
  166.  
  167.     (*** The judge delivers the sentence ***)
  168.  
  169.     !BeginJudge
  170.     Guilty!  Life!
  171.     !EndJudge
  172.  
  173.  
  174.     Gulty!  Life!
  175.  
  176. Note that the end token for Percy was not properly specified.  They are
  177. case sensitive.  Since it never found the specified end token, the
  178. function returned the entire file from begin-token to end-of-file.
  179. This included all the other begin and end tokens, all the inbetween texts -
  180. all because the end token you specified didn't exist!
  181.  
  182. Be careful with your token naming scheme.  I suggest using a standard
  183. say, ALL CAPS with only a preceeding ":" for instance.
  184.  
  185. On NEXT call the function found it's delimiting tokens with no problem
  186. and returned the (now duplicated) "Guilty!  Life!!" sentence.
  187.  
  188. ******************************************************************************/
  189.